package com.itcanteen.medical.docker.controller;

import com.itcanteen.medical.common.vo.CommonResponse;
import com.itcanteen.medical.docker.entity.Doctor;
import com.itcanteen.medical.docker.service.DoctorService;
import com.itcanteen.medical.docker.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;

@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    //医生点击上班
    @GetMapping("/sendMsgToPatient")
    @ApiOperation("通知患者就诊")
    public CommonResponse sendMsgToPatient(String name) throws IOException, TimeoutException {
        //修改当前医生上班状态
        doctorService.updateStatus(name);
        //给预约患者群发消息
        doctorService.sendMsgToPatient(name);
        return new CommonResponse(1,"mq发消息成功",null);
    }


    @GetMapping("/findList")
    @ApiOperation("查询所有医生")
    public List<Doctor> findList(){
        return doctorService.findList();
    }

    @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
    @ApiOperation("上传图片")
    public Result uploadFile(Long id, MultipartFile multipartFile) throws IOException {
        try {
            doctorService.uploadFile(id,multipartFile);
            return new Result(true,"上传成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"上传失败");
        }
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ApiOperation("人识别登录")
    public Result login(String username, MultipartFile multipartFile) throws IOException {
        Boolean aBoolean = doctorService.login(username,multipartFile);
        if(aBoolean == true){
            return new Result(true,"登录成功");
        }else{
            return new Result(false,"登陆失败");
        }
    }
}
